﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void loginzc_Click(object sender, EventArgs e)
    {
        HttpContext.Current.Response.Redirect("register.aspx");
    }

    protected void loginbt_Click(object sender, EventArgs e)
    {
        string sname, spsd;
        sname = loginnametext.Text;
        spsd = loginpswtext.Text;
        SqlConnection con = new SqlConnection("Data Source =.; Initial Catalog = smdb; Integrated Security = True");
        con.Open();
        string sql = string.Format("select count(*) from users where name='{0}' and psd='{1}'", sname, spsd);//这里你自己改改了，不知道你用什么登陆的，账号密码不知道你用什么字段,暂时认为你用学号跟姓名登陆  
        SqlCommand com = new SqlCommand(sql, con);
        int flag = (int)com.ExecuteScalar();
        con.Close();
        if (flag > 0)
        {
            Session["username"] = sname;
            HttpContext.Current.Response.Redirect("MessageBoard.aspx");
        }
       else
            Response.Write("<script>alert('用户名或者密码出错！');</script>");
    }
}
